// Title: Vision
// Author: Patricio Gonzalez Vivo

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;

#include "../lib/fill.glsl"
#include "../lib/stroke.glsl"
#include "../lib/raysSDF.glsl"
#include "../lib/circleSDF.glsl"
#include "../lib/vesicaSDF.glsl"

void main() {
    vec3 color = vec3(0.);
    vec2 st = gl_FragCoord.xy/u_resolution;
    st = (st-.5)*1.1912+.5;
    if (u_resolution.y > u_resolution.x ) {
        st.y *= u_resolution.y/u_resolution.x;
        st.y -= (u_resolution.y*.5-u_resolution.x*.5)/u_resolution.x;
    } else {
        st.x *= u_resolution.x/u_resolution.y;
        st.x -= (u_resolution.x*.5-u_resolution.y*.5)/u_resolution.y;
    }
    //START
    float v1 = vesicaSDF(st,.5);
    vec2 st2 = st.yx+vec2(.04,.0);
    float v2 = vesicaSDF(st2,.7);
    color += stroke(v2,1.,.05);
    color += fill(v2,1.)*
             stroke(circleSDF(st),.3,.05);
    color += fill(raysSDF(st,50),.2)*
             fill(v1,1.25)*
             step(1.,v2);
    //END
    gl_FragColor = vec4(color,1.);
}